/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets;

import beans.Usuario;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HolaMundo extends HttpServlet {

    private Usuario[] arr = new Usuario[3];


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       response.setContentType("text/html;charset=UTF-8");
        arr[0] = new Usuario("aLex", "hola123");
        arr[1] = new Usuario("pepe", "eltoro");
        arr[2] = new Usuario("juanito", "banana");

        PrintWriter pw = response.getWriter();
        String u = request.getParameter("usuario");
        String p = request.getParameter("pass");

        Usuario us = new Usuario(u, p);

        boolean existe = false;
        for (Usuario temp : arr) {
            if (temp.getUsuario().equals(us.getUsuario()) && temp.getPassword().equals(us.getPassword())) {
                existe = true;
                break;

            }
        }
        if (!existe) {
            response.sendRedirect("index.jsp");
        } else {
            response.sendRedirect("bienvenido.jsp");
        }

    }
    
}
